home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wfc007.000 / include / cregisty.hpp < prev    next >
C/C++ Source or Header  |  1996-04-08  |  8KB  |  229 lines

  1. #if ! defined( REGISTRY_CLASS_HEADER )
  2.  
  3. /*
  4. ** Author: Samuel R. Blackburn
  5. ** CI$: 76300,326
  6. ** Internet: sammy@sed.csc.com
  7. **
  8. ** You can use it any way you like.
  9. */
  10.  
  11. #define REGISTRY_CLASS_HEADER
  12.  
  13. #define THIS_SUB_KEY FALSE
  14. #define ALL_SUB_KEYS TRUE
  15.  
  16. #define SIGNAL_EVENT    TRUE
  17. #define WAIT_FOR_CHANGE FALSE
  18.  
  19. class CRegistry : public CObject
  20. {
  21.    DECLARE_DYNAMIC( CRegistry )
  22.  
  23.    private:
  24.  
  25.       HKEY m_KeyHandle;
  26.       HKEY m_RegistryHandle;
  27.  
  28.       void m_Initialize( void );
  29.  
  30.    protected:
  31.  
  32.       LONG m_ErrorCode;
  33.  
  34.       /*
  35.       ** Data items filled in by QueryInfo
  36.       */
  37.  
  38.       DWORD    m_LongestSubkeyNameLength;
  39.       DWORD    m_LongestClassNameLength;
  40.       DWORD    m_LongestValueNameLength;
  41.       DWORD    m_LongestValueDataLength;
  42.       DWORD    m_SecurityDescriptorLength;
  43.       FILETIME m_LastWriteTime;
  44.  
  45.    public:
  46.  
  47.       static const HKEY keyLocalMachine;
  48.       static const HKEY keyClassesRoot;
  49.       static const HKEY keyUsers;
  50.       static const HKEY keyCurrentUser;
  51.       
  52.       enum KeyValueTypes
  53.       {
  54.          typeBinary                 = REG_BINARY,
  55.          typeDoubleWord             = REG_DWORD,
  56.          typeDoubleWordLittleEndian = REG_DWORD_LITTLE_ENDIAN,
  57.          typeDoubleWordBigEndian    = REG_DWORD_BIG_ENDIAN,
  58.          typeUnexpandedString       = REG_EXPAND_SZ,
  59.          typeSymbolicLink           = REG_LINK,
  60.          typeMultipleString         = REG_MULTI_SZ,
  61.          typeNone                   = REG_NONE,
  62.          typeResourceList           = REG_RESOURCE_LIST,
  63.          typeString                 = REG_SZ
  64.       };
  65.  
  66.       enum CreateOptions
  67.       {
  68.          optionsNonVolatile = REG_OPTION_NON_VOLATILE,
  69.          optionsVolatile    = REG_OPTION_VOLATILE
  70.       };
  71.  
  72.       enum CreatePermissions
  73.       {
  74.          permissionAllAccess        = KEY_ALL_ACCESS,
  75.          permissionCreateLink       = KEY_CREATE_LINK,
  76.          permissionCreateSubKey     = KEY_CREATE_SUB_KEY,
  77.          permissionEnumerateSubKeys = KEY_ENUMERATE_SUB_KEYS,
  78.          permissionExecute          = KEY_EXECUTE,
  79.          permissionNotify           = KEY_NOTIFY,
  80.          permissionQueryValue       = KEY_QUERY_VALUE,
  81.          permissionRead             = KEY_READ,
  82.          permissionSetValue         = KEY_SET_VALUE,
  83.          permissionWrite            = KEY_WRITE
  84.       };
  85.  
  86.       enum CreationDisposition
  87.       {
  88.          dispositionCreatedNewKey     = REG_CREATED_NEW_KEY,
  89.          dispositionOpenedExistingKey = REG_OPENED_EXISTING_KEY
  90.       };
  91.  
  92.       enum NotifyChangeFlag
  93.       {
  94.          changeKeyAndSubkeys    = TRUE,
  95.          changeSpecifiedKeyOnly = FALSE
  96.       };
  97.  
  98.       enum NotifyChangeFilter
  99.       {
  100.          notifyName       = REG_NOTIFY_CHANGE_NAME,
  101.          notifyAttributes = REG_NOTIFY_CHANGE_ATTRIBUTES,
  102.          notifyLastSet    = REG_NOTIFY_CHANGE_LAST_SET,
  103.          notifySecurity   = REG_NOTIFY_CHANGE_SECURITY
  104.       };
  105.  
  106.       CRegistry();
  107.  
  108.       /*
  109.       ** Destructor should be virtual according to MSJ article in Sept 1992
  110.       ** "Do More with Less Code:..."
  111.       */
  112.  
  113.       virtual ~CRegistry();
  114.  
  115.       /*
  116.       ** Data
  117.       */
  118.  
  119.       CString ClassName;
  120.       CString ComputerName;
  121.       CString KeyName;
  122.       CString RegistryName;
  123.       DWORD   NumberOfSubkeys;
  124.       DWORD   NumberOfValues;
  125.       CTime   LastWriteTime;
  126.  
  127.       /*
  128.       ** Methods
  129.       */
  130.  
  131.       virtual BOOL Close( void );
  132.  
  133.       virtual BOOL Connect( HKEY    key_to_open   = HKEY_CURRENT_USER,
  134.                             LPCTSTR computer_name = NULL );
  135.  
  136.       virtual BOOL Create( LPCTSTR               name_of_subkey,
  137.                            LPCTSTR               name_of_class         = NULL,
  138.                            CreateOptions         options               = optionsNonVolatile,
  139.                            CreatePermissions     permissions           = permissionAllAccess,
  140.                            LPSECURITY_ATTRIBUTES security_attributes_p = NULL,
  141.                            CreationDisposition * disposition_p         = NULL );
  142.  
  143.       virtual BOOL DeleteKey( LPCTSTR name_of_subkey_to_delete );
  144.  
  145.       virtual BOOL DeleteValue( LPCTSTR name_of_value_to_delete );
  146.  
  147.       virtual BOOL EnumerateKeys( const DWORD subkey_index,
  148.                                   CString&    subkey_name,
  149.                                   CString&    class_name );
  150.  
  151.       virtual BOOL EnumerateValues( const DWORD    value_index,
  152.                                     CString&       name_of_value,
  153.                                     KeyValueTypes& type_code,
  154.                                     LPBYTE         data_buffer,
  155.                                     DWORD&         size_of_data_buffer );
  156.  
  157.       virtual BOOL Flush( void );
  158.  
  159.       virtual BOOL GetBinaryValue( LPCTSTR name_of_value, CByteArray& return_array );
  160.  
  161.       virtual BOOL GetDoubleWordValue( LPCTSTR name_of_value, DWORD& return_value );
  162.  
  163.       virtual BOOL GetErrorCode( void ) const;
  164.  
  165.       virtual BOOL GetSecurity( const SECURITY_INFORMATION what_you_want_to_know,
  166.                                 PSECURITY_DESCRIPTOR       data_buffer,
  167.                                 DWORD&                     size_of_data_buffer );
  168.  
  169.       virtual BOOL GetStringValue( LPCTSTR name_of_value, CString& return_string );
  170.       
  171.       virtual BOOL GetStringArrayValue( LPCTSTR name_of_value, CStringArray& return_array );
  172.  
  173.       virtual BOOL GetValue( LPCTSTR name_of_value, CByteArray& return_array );
  174.       virtual BOOL GetValue( LPCTSTR name_of_value, DWORD& return_value );
  175.       virtual BOOL GetValue( LPCTSTR name_of_value, CString& return_string );
  176.       virtual BOOL GetValue( LPCTSTR name_of_value, CStringArray& return_array );
  177.  
  178.       virtual BOOL Load( LPCTSTR name_of_subkey,
  179.                          LPCTSTR name_of_file_containg_information );
  180.  
  181.       virtual BOOL NotifyChange( const HANDLE event_handle                       = NULL,
  182.                                  const NotifyChangeFilter changes_to_be_reported = notifyLastSet,
  183.                                  const BOOL this_subkey_or_all_subkeys           = changeSpecifiedKeyOnly,
  184.                                  const BOOL wait_for_change_or_signal_event      = WAIT_FOR_CHANGE );
  185.  
  186.       virtual BOOL Open( LPCTSTR name_of_subkey_to_open,
  187.                          const CreatePermissions security_access_mask = permissionAllAccess );
  188.  
  189.       virtual BOOL QueryInfo( void );
  190.  
  191.       virtual BOOL QueryValue( LPCTSTR        name_of_value,
  192.                                KeyValueTypes& value_type,
  193.                                LPBYTE         address_of_buffer,
  194.                                DWORD&         size_of_buffer );
  195.  
  196.       virtual BOOL Replace( LPCTSTR name_of_subkey,
  197.                             LPCTSTR name_of_file_with_new_data,
  198.                             LPCTSTR name_of_backup_file );
  199.  
  200.       virtual BOOL Restore( LPCTSTR name_of_file_holding_saved_tree, const DWORD volitility_flags = NULL );
  201.  
  202.       virtual BOOL Save( LPCTSTR name_of_file_to_hold_tree, LPSECURITY_ATTRIBUTES security_attributes_p = NULL );
  203.  
  204.       virtual BOOL SetBinaryValue( LPCTSTR name_of_value, const CByteArray& bytes_to_write );
  205.  
  206.       virtual BOOL SetDoubleWordValue( LPCTSTR name_of_value, DWORD value_to_write );
  207.  
  208.       virtual BOOL SetSecurity( const SECURITY_INFORMATION& security_information,
  209.                                 const PSECURITY_DESCRIPTOR security_descriptor_p );
  210.  
  211.       virtual BOOL SetStringValue( LPCTSTR name_of_value, const CString& string_value );
  212.  
  213.       virtual BOOL SetStringArrayValue( LPCTSTR name_of_value, const CStringArray& string_array );
  214.  
  215.       virtual BOOL SetValue( LPCTSTR name_of_value, const CByteArray& bytes_to_write );
  216.       virtual BOOL SetValue( LPCTSTR name_of_value, DWORD value );
  217.       virtual BOOL SetValue( LPCTSTR name_of_value, const CStringArray& strings_to_write );
  218.       virtual BOOL SetValue( LPCTSTR name_of_value, const CString& string_to_write );
  219.  
  220.       virtual BOOL SetValue( LPCTSTR             name_of_subkey,
  221.                              const KeyValueTypes type_of_value_to_set,
  222.                              CONST PBYTE         address_of_value_data,
  223.                              const DWORD         size_of_data );
  224.  
  225.       virtual BOOL UnLoad( LPCTSTR name_of_subkey_to_unload );
  226. };
  227.  
  228. #endif // REGISTRY_CLASS_HEADER
  229.